#!/bin/bash
BASEDIR=$(cd $(dirname "$0"); pwd -P)
set -exo pipefail
cd $BASEDIR

# 更新本地White-bridge build, 第二个参数可以控制bridge的地址
if (! [ -z $2 ]); then
BRIDGEDIR=$2
else
BRIDGEDIR=../Whiteboard-bridge
fi
cd $BRIDGEDIR
yarn

if (! [ -z $1 ])&&[ $1 = 'debug' ]; then
yarn buildDev
else
yarn build
fi

# 清理bridge不需要的资源
git clean -fd

cd $BASEDIR

# 设置 white-sdk web 资源的目标
export TargetPath="./Whiteboard/Resource"
export SourcePath="$BRIDGEDIR/build"

# 删除并创建文件目录
rm -rf $TargetPath
mkdir -p $TargetPath
# 从 bridge 复制构建好的 web 资源
cp -r $SourcePath/* $TargetPath/

# 清理 build 文件，否则在 .bundle 里的静态资源文件无法更新
rm -rf ~/Library/Developer/Xcode/DerivedData/WhiteSDKPrivate-*/Build/Products/

cd $BASEDIR/Example
pod install

# 更新与 bridge 的关联
cd $BASEDIR
rabbit update